<?php

namespace App\Common\Model\Base;

use App\Common\Model\Attribute\CreateSql;
use App\Common\Model\Attribute\InitData;
use App\Common\Model\Model;

/**
 * 路由菜单
 * @property int    $id          ID
 * @property int    $pid         父级
 * @property int    $type        类型
 * @property string $title       标题
 * @property string $icon        图标
 * @property string $route       路由
 * @property string $power_route 权限路由
 * @property int    $weigh       排序
 * @property string $create_time 创建时间
 * @property string $update_time 更新时间
 * @property int    $delete_time 删除时间
 */
#[CreateSql(<<<SQL
CREATE TABLE `sc_route` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `pid` int(11) NOT NULL DEFAULT '0' COMMENT '父级',
  `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类型：1=左侧菜单，2=页面操作，3=头部菜单',
  `title` varchar(32) NOT NULL DEFAULT '' COMMENT '标题',
  `icon` varchar(32) NOT NULL DEFAULT '' COMMENT '图标',
  `route` varchar(64) NOT NULL DEFAULT '' COMMENT '路由',
  `power_route` json DEFAULT NULL COMMENT '权限路由',
  `weigh` int(11) NOT NULL DEFAULT '1' COMMENT '排序',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='路由菜单';
SQL)]
#[InitData([
    "INSERT INTO `sc_route`(`id`, `pid`, `type`, `title`, `icon`, `route`, `power_route`, `weigh`, `create_time`, `update_time`, `delete_time`) VALUES (1, 0, 1, '系统设置', 'Setting', '', '[]', 1, '2022-03-30 02:23:04', '2023-08-16 15:10:02', NULL);",
    "INSERT INTO `sc_route`(`id`, `pid`, `type`, `title`, `icon`, `route`, `power_route`, `weigh`, `create_time`, `update_time`, `delete_time`) VALUES (2, 1, 1, '路由设置', 'Connection', 'base/route/lists', '[]', 3, '2022-03-30 02:25:29', '2023-08-16 15:15:28', NULL);",
    "INSERT INTO `sc_route`(`id`, `pid`, `type`, `title`, `icon`, `route`, `power_route`, `weigh`, `create_time`, `update_time`, `delete_time`) VALUES (3, 1, 1, '管理员管理', 'Avatar', 'base/administrators/lists', '[]', 4, '2022-03-30 02:26:31', '2023-08-16 15:09:24', NULL);",
    "INSERT INTO `sc_route`(`id`, `pid`, `type`, `title`, `icon`, `route`, `power_route`, `weigh`, `create_time`, `update_time`, `delete_time`) VALUES (4, 1, 1, '角色管理', 'UserFilled', 'base/role/lists', '[]', 3, '2022-04-14 23:43:41', '2023-08-16 15:11:05', NULL);",
    "INSERT INTO `sc_route`(`id`, `pid`, `type`, `title`, `icon`, `route`, `power_route`, `weigh`, `create_time`, `update_time`, `delete_time`) VALUES (5, 1, 1, '配置中心', 'Cpu', 'base/super-config/lists', '[]', 3, '2022-05-06 08:22:47', '2023-08-16 15:11:40', NULL);",
])]
class Route extends Model
{

    protected $schema = [
        'id'          => 'int',
        'pid'         => 'int',
        'type'        => 'tinyint',
        'title'       => 'varchar',
        'icon'        => 'varchar',
        'route'       => 'varchar',
        'power_route' => 'json',
        'weigh'       => 'int',
        'create_time' => 'datetime',
        'update_time' => 'datetime',
        'delete_time' => 'int',
    ];

    protected $type = [
        ...self::DEFAULT_CASTS,
        'power_route' => 'array'
    ];

    protected $field = ['pid', 'type', 'title', 'icon', 'route', 'power_route', 'weigh',];
}

